package cate.game.activity.crossrank.handler;

import cate.common.table.activity.crossrankactivity.row.CrossRankActivityBaseRow;
import cate.common.util.GameResult;
import cate.game.GameBody;
import cate.game.activity.crossrank.po.CrossRankActivity;
import cate.game.rank.cross.h.BaseCrossRankLoader;
import cate.game.role.Role;
import org.springframework.data.annotation.Transient;

/**
 * 跨服排行活动处理器
 */
public class CrossRankActivityLoader extends BaseCrossRankLoader {
    /**
     * 配置Tid
     */
    public int configTid;

    @Transient
    protected GameBody game;

    public CrossRankActivityLoader() {

    }

    public CrossRankActivityLoader(GameBody game, int rankId, int configTid) {
        super(rankId);
        this.configTid = configTid;
        this.game = game;
    }

    @Override
    public long getRoleCurrentValue(Role role) {
        CrossRankActivity activity = role.getActivity().getEnableActivitySingle(getConfig().funcId);
        if (activity == null) {
            return 0;
        }
        return activity.rankValue;
    }

    @Override
    public long getRoleCurrentExtraValue(Role role) {
        return 0;
    }

    @Override
    public long getConditionValue() {
        return getConfig().condition;
    }

    /**
     * 获取基础配置
     */
    public CrossRankActivityBaseRow getConfig() {
        return game.table.crossRankActivity.base.get(configTid);
    }

    @Override
    public GameResult<Void> sendCrossRankList(Role role, int limitOrigin) {
        CrossRankActivityBaseRow config = getConfig();
        int limit = (limitOrigin <= 0 || limitOrigin > config.watchMax) ? config.watchMax : limitOrigin;
        return super.sendCrossRankList(role, limit);
    }
}
